#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int tribonacci(int n) {
        if (n == 0)
            return 0;
        if (n == 1 || n == 2)
            return 1;

        int feb[3] = { 1, 1, 0 };
        for (int i = 3; i <= n; i++)
        {
            int tmp = feb[0] + feb[1] + feb[2];
            feb[2] = feb[1];
            feb[1] = feb[0];
            feb[0] = tmp;
        }

        return feb[0];
    }
};